package com.changzhi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.changzhi.common.constans.RedisConstans;
import com.changzhi.ldyl.model.ChatChannel;
import com.changzhi.mapper.ChatChannelMapper;
import com.changzhi.service.ChatChannelService;
import com.changzhi.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description:
 * @author: 小落
 * @date: 2020年11月17日
 */
@Service
public class ChatChannelServiceImpl extends ServiceImpl<ChatChannelMapper, ChatChannel> implements ChatChannelService {

	@Autowired
	private RedisUtil redisUtil;

	@Override
	public ChatChannel getChatChannel(String channelId) {
		ChatChannel chatChannel = redisUtil.get(RedisConstans.CHANNEL + channelId);
		if (chatChannel == null) {
			QueryWrapper<ChatChannel> condition = new QueryWrapper<>();
			condition.lambda().eq(ChatChannel::getChannelId, channelId);
			chatChannel = baseMapper.selectOne(condition);
		}
		return chatChannel;
	}

}
